// ============================================================================
//
// Copyright (C) 2006-2007 Dengues
//
// Google Group: http://groups.google.com/group/dengues
// QQ Group: 24885404
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
// ============================================================================
package org.dengues.designer.core.shadow;

import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.Properties;

import org.dengues.commons.connectivity.IConnectivitySettingsConstants;
import org.dengues.core.components.IXMLComponent;
import org.dengues.core.process.CompElement;
import org.dengues.core.process.ICompConnection;
import org.dengues.core.process.ICompNode;
import org.dengues.core.process.ICompProcess;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Point;

/**
 * Qiang.Zhang.Adolf@gmail.com class global comment. Detailled comment <br/>
 * 
 * $Id: Dengues.epf 1 2006-09-29 17:06:40Z qiang.zhang $
 * 
 */
public class ShadowCompNode extends CompElement implements ICompNode {

    private static final long serialVersionUID = 145648874322L;

    private final List<ICompConnection> incomingConnections;

    private final List<ICompConnection> outgoingConnections;

    private final IXMLComponent component;

    private ShadowCompProcess compProcess;

    /**
     * Qiang.Zhang.Adolf@gmail.com ShadowCompNode constructor comment.
     * 
     * @param compProcess
     * @param component
     */
    public ShadowCompNode(ShadowCompProcess compProcess, IXMLComponent component) {
        this.component = component;
        this.compProcess = compProcess;
        incomingConnections = new ArrayList<ICompConnection>();
        outgoingConnections = new ArrayList<ICompConnection>();
        init(component);
    }

    /**
     * Qiang.Zhang.Adolf@gmail.com ShadowCompNode constructor comment.
     * 
     * @param component
     */
    public ShadowCompNode(IXMLComponent component) {
        this.component = component;
        incomingConnections = new ArrayList<ICompConnection>();
        outgoingConnections = new ArrayList<ICompConnection>();
        init(component);
    }

    /**
     * Qiang.Zhang.Adolf@gmail.com ShadowCompNode constructor comment.
     * 
     * @param component
     * @param properties
     */
    public ShadowCompNode(IXMLComponent component, Properties properties) {
        this(component);
        Enumeration baseProperties = properties.keys();
        while (baseProperties.hasMoreElements()) {
            String id = (String) baseProperties.nextElement();
            if (id.startsWith(IConnectivitySettingsConstants.PROP_PREFIX)) {
                String string = id.substring(IConnectivitySettingsConstants.PROP_PREFIX.length());
                setNodeParameterValue(string.toUpperCase(), properties.get(id));
            }
        }
    }

    /**
     * Qiang.Zhang.Adolf@gmail.com Comment method "init".
     * 
     * @param component2
     */
    private void init(IXMLComponent component2) {
        setElementParameters(component.createNodeParameters(this));
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.dengues.core.process.ICompNode#addIncomingConnections(org.dengues.core.process.ICompConnection)
     */
    public void addIncomingConnections(ICompConnection incomingConnection) {

    }

    /*
     * (non-Javadoc)
     * 
     * @see org.dengues.core.process.ICompNode#addOutgoingConnections(org.dengues.core.process.ICompConnection)
     */
    public void addOutgoingConnections(ICompConnection outgoingConnection) {

    }

    /*
     * (non-Javadoc)
     * 
     * @see org.dengues.core.process.ICompNode#checkNode()
     */
    public void checkNode() {

    }

    /*
     * (non-Javadoc)
     * 
     * @see org.dengues.core.process.ICompNode#getCompName()
     */
    @Override
    public String getCompName() {
        return component.getName();
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.dengues.core.process.ICompNode#getComponent()
     */
    public IXMLComponent getComponent() {
        return component;
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.dengues.core.process.ICompNode#getIncomingConnections()
     */
    public List<? extends ICompConnection> getIncomingConnections() {
        return incomingConnections;
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.dengues.core.process.ICompNode#getOutgoingConnections()
     */
    public List<? extends ICompConnection> getOutgoingConnections() {
        return outgoingConnections;
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.dengues.core.process.ICompNode#getUniqueName()
     */
    public String getUniqueName() {
        return "shadow_" + component.getName(); //$NON-NLS-1$
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.dengues.core.process.ICompNode#isStart()
     */
    public boolean isStart() {
        return false;
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.dengues.core.process.ICompNode#isSubProcessStart()
     */
    public boolean isSubProcessStart() {
        return false;
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.dengues.core.process.ICompNode#removeIncomingConnections(org.dengues.core.process.ICompConnection)
     */
    public void removeIncomingConnections(ICompConnection incomingConnection) {

    }

    /*
     * (non-Javadoc)
     * 
     * @see org.dengues.core.process.ICompNode#removeOutgoingConnections(org.dengues.core.process.ICompConnection)
     */
    public void removeOutgoingConnections(ICompConnection outgoingConnection) {

    }

    /*
     * (non-Javadoc)
     * 
     * @see org.dengues.core.process.CompElement#getCompProcess()
     */
    @Override
    public ICompProcess getCompProcess() {
        return compProcess;
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.dengues.core.process.CompElement#getLocation()
     */
    @Override
    public Point getLocation() {
        return new Point(0, 0);
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.dengues.core.process.CompElement#getSize()
     */
    @Override
    public Dimension getSize() {
        return new Dimension(0, 0);
    }

    /**
     * Sets the compProcess.
     * 
     * @param compProcess the compProcess to set
     */
    public void setCompProcess(ShadowCompProcess compProcess) {
        this.compProcess = compProcess;
    }

}
